package com.dartsstats;

import com.dartsstats.R;
import com.dartsstats.R.id;
import com.dartsstats.R.layout;
import com.dartsstats.R.menu;
import com.dartsstats.datasource.GameDataSource;
import com.dartsstats.datasource.MatchDataSource;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class GameActivity extends Activity {
	
	private Game game;
	private Match match;
	private GameState gameState;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_game);
		Bundle extras = getIntent().getExtras();
		long gameID = -1;
		long matchID = -1;
		if(extras != null) {
			gameID = extras.getLong("GAME_ID");
			game = new GameDataSource(this).getGameByID((int)gameID);
			matchID = extras.getLong("MATCH_ID");
			match = new MatchDataSource(this).getMatchByID((int)matchID);
			gameState = new GameState(gameID, matchID, this);
			
			TextView homeScoreTextView = (TextView) findViewById(R.id.homeScoreTextView);
			homeScoreTextView.setText("0");
			TextView awayScoreTextView = (TextView) findViewById(R.id.awayScoreTextView);
			awayScoreTextView.setText("0");
			TextView playerAtBatTextView = (TextView) findViewById(R.id.playerAtBatTextView);
			playerAtBatTextView.setText(gameState.getCurrentAwayBatter().toString());
			populateHitTypeSpinner();
		}
	}

	private void populateHitTypeSpinner() {
		Spinner spinner = (Spinner) findViewById(R.id.hitTypeSpinner);
		ArrayAdapter<Result> adapter = new ArrayAdapter<Result>(this,
				android.R.layout.simple_spinner_item, Result.values());
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_game, menu);
		return true;
	}

}
